package com.infonam.jsf.eshop.execute;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import com.infonam.jsf.eshop.model.UserHolder;

@ManagedBean(name="confirmService")
@RequestScoped
public class ConfirmService {
	@ManagedProperty(value="#{cart}")
	private Cart cart;
	@ManagedProperty(value="#{catalog}")
	private Catalog catalog;
	@ManagedProperty(value="#{userHolder}")
	private UserHolder uh;

	public double getTotal() {
		double total = 0;
		for (String pid : cart.getProductIds()) {
			total += catalog.getProduct(pid).getPrice();
		}
		return total;
	}

	public String getCreditCardNo() {
		return uh.getCurrentUser().getCreditCardNo();
	}
	public Cart getCart() {
		return cart;
	}

	public void setCart(Cart cart) {
		this.cart = cart;
	}

	public Catalog getCatalog() {
		return catalog;
	}

	public void setCatalog(Catalog catalog) {
		this.catalog = catalog;
	}

	public UserHolder getUh() {
		return uh;
	}

	public void setUh(UserHolder uh) {
		this.uh = uh;
	}

}